package com.nowcoder.Offer.Array;

import org.junit.Test;

/**
 * 构建乘积数组
 */
public class BuildMultiplyArray {
    public int[] multiply(int[] A){
        int cur = A[0];
        int[] B = new int[A.length];

        for(int i=0; i<A.length; i++){
            B[i] = cur;
            cur *= A[i];
        }

        cur = 1;

        for(int i=A.length-1; i>=0; i--){
            B[i] *= cur;
            cur *= A[i];
        }

        return B;
    }

    @Test
    public void test(){
        int[] A = {1,2,3,4,5};
        for(int i: multiply(A)){
            System.out.print(i +" ");
        }
    }
}
